﻿@model XSTDZ.ERP.Application.DataContracts.UsualFinanceDto
@using XSTDZ.ERP.Infrastructure.Extentions
@{
    ViewBag.Title = " - 编辑日常开支";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
     <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
}


<div class="wp100">
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            </th>
        </tr>
    </thead>
    <tr>

        <td class="title">@*@Html.LabelFor(model => model.OrgName)*@组织机构<b>*</b></td>
        <td>  @Html.TextBoxFor(model => model.OrgName,new { @class ="text disablebg", @readonly = "readonly" })
            @Html.ValidationMessageFor(model => model.OrgId)
             @Html.HiddenFor(model => model.Id)
              @Html.HiddenFor(model => model.OrgId)
               @Html.HiddenFor(model => model.BillState)
         </td>
        <td class="title">@Html.LabelFor(model => model.Remark)</td>
        <td > @Html.TextBoxFor(model => model.Remark, new { @class = "text" })
            @Html.ValidationMessageFor(model => model.Remark)
            <input id="HidProjectTypeItems" name="HidProjectTypeItems" type="hidden" value="@ViewBag.ProjectTypeItems" />
            <input id="HidtempId" name="HidtempId" type="hidden" value="@Guid.Empty" />
             <input type="hidden" value="" name="hidProductBillItems" id="hidProductBillItems" />
         </td>
  </tr> 
       
 <tr>
        <td  colspan="4">
              <p class="divBtn">
              <input id="HidTempDate" name="HidTempDate" type="hidden" value="@DateTime.Today.ToString("yyyy-MM-dd")" />
              <input id="HidOrgCode" name="HidOrgCode" type="hidden" value="@ViewBag.OrgCode" />
               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            
           
            <input type="submit" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"  class="BtnSubmit" id="submitBtn" name="submitBtn" />
            <input type="submit" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSubmit"  class="BtnSubmit" id="btnSubmit" name="btnSubmit" />
          @*  <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnClose" id="btnFromClose" name="btnFromClose" class="BtnClose" />*@
        </p>
        </td>
    </tr>
    </table>
}
   <input type="hidden" id="hidHttpPostState" name="hidHttpPostState" value="@ViewBag.PostState" />
</div>
<div class="wp100">
<div id="BillItemsGrid" style="margin-top:20px" ></div>
</div>

<script type="text/javascript">
   

    $(document).ready(function () {
//        $("#HandlingTime").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left'
//        });
//        var productInDateVal = $("#HandlingTimeVal").val();
//        $("#HandlingTime").ligerGetDateEditorManager().setValue(productInDateVal);

//        //经办人
//        $("#OperatorName").ligerPopupEdit({
//            grid: getUserGridOptions(false),
//            valueField: 'Key',
//            textField: 'Name'
        //        });



        $("#submitBtn").unbind("click").bind("click", function () { getProductBillItemData(false); }); //保存
        $("#btnSubmit").unbind("click").bind("click", function () { getProductBillItemData(true); }); //提交

    });

      //保存或提交都调用同一个方法
    //参数：isSave [是否为保存]
    function getProductBillItemData(isConfirm) {
        if ($("#BillState").val() == "1") { $.ligerDialog.success("已提交，不能再更新!"); }
        else {
            if (manager != null && manager != undefined) {
               // if (!validateGridDetail(manager, "SenderCount")) { $.ligerDialog.success('明细数量不能小于0!'); return; }; //验证明细
                var data = manager.getData();
                $("#hidProductBillItems").val("").val(JSON.stringify(data));
                var btnText = ""; //
                if (!isConfirm) {
                    btnText = $("#submitBtn").val();
                    $("#submitBtn").val("").val("正在处理中...");
                }
                else {
                    btnText = $("#btnSubmit").val();
                    $("#btnSubmit").val("").val("正在处理中...");
                }
                //$.ajax({ type: "POST", url: "/ProductDelivery/Add", data: $("form").serialize(), // 要提交的表单
                $.ajax({ type: "POST", url: "/UsualFinance/AddAndConfirm?isConfirm=" + isConfirm, data: $("form").serialize(), // 要提交的表单
                    success: function (msg) {
                        if (msg == "9") {
                            $.ligerDialog.success('操作成功!');
                            initligerGrid();
                            ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                        }
                        else if (msg == "0") {
                            $.ligerDialog.success('数据不完整!');
                        }
                        else if (msg == "-1") {
                            $.ligerDialog.success('操作异常!');
                        }
                        else if (msg != undefined && $.trim(msg).length > 10) {
                            $.ligerDialog.success('操作成功!');
                            $("#Id").val("").val(msg);
                            //initligerGrid();
                            ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                        }
                        else {
                            $.ligerDialog.success('操作失败!');
                        }
                        if (!isConfirm) { $("#submitBtn").val("").val(btnText); } else { $("#btnSubmit").val("").val(btnText); }
                    }
                });
            }
        }
    }

</script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerPopupEdit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerDateEditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/UsualFinance/Add.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/SelectData.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>
